﻿using UnityEngine;
using System.Collections;

public class IntVector2  {

	public int x;
	public int y;


	public float magnitude{
		get{
			return Mathf.Sqrt(x*x+y*y);
		}
	}
	public float sqrMagnitude{
		get{
			return x*x+y*y;
		}
	}

	public IntVector2(int x=0, int y=0)
	{
		this.x=x;
		this.y=y;
	}
	public override string ToString ()
	{
		return string.Format ("[IntVector2: x={0}, y={1}]", x, y);
	}

	#region static func

	public static IntVector2 zero{
		get{return new IntVector2();}
	}

	public static float Distance(IntVector2 l, IntVector2 r)
	{
		return (l-r).magnitude;
	}

	public static IntVector2 operator + (IntVector2 a, IntVector2 b)
	{
		return new IntVector2(a.x+b.x, a.y+b.y);
	}

	public static IntVector2 operator / (IntVector2 a, float d)
	{
		return new IntVector2((int)(a.x/d), (int)(a.y/d));
	}

	public static bool operator == (IntVector2 lhs, IntVector2 rhs)
	{
		if(object.Equals(lhs, null) || object.Equals(rhs, null))
		{
			return object.Equals(lhs, rhs);
		}
		return lhs.x==rhs.x && lhs.y==rhs.y;
	}

	public static bool operator != (IntVector2 lhs, IntVector2 rhs)
	{
		return !( lhs==rhs );
	}

	public static IntVector2 operator * (IntVector2 a, float d)
	{
		return new IntVector2((int)(a.x*d), (int)(a.y*d));
	}

	public static IntVector2 operator * (float d, IntVector2 a)
	{
		return new IntVector2((int)(a.x*d), (int)(a.y*d));
	}

	public static IntVector2 operator - (IntVector2 a, IntVector2 b)
	{
		return new IntVector2(a.x-b.x, a.y-b.y);
	}

	public static IntVector2 operator - (IntVector2 a)
	{
		return new IntVector2(-a.x, -a.y);
	}
	#endregion
}
